var NNum=0;
function createXmlDoc()
{
	var _bool_IE = ( window.ActiveXObject ? true : false );
	var _obj_xmlDoc; 
    if( _bool_IE ) 
    	{
        	_obj_xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
        } 
    else 
    	{
        	_obj_xmlDoc = document.implementation.createDocument("","",null);
        } 
     return _obj_xmlDoc;
}
function showSubMenu1()
{
	var eID = event.srcElement.parentNode;
	var ful=eID.getAttribute("id");
	var sul="c"+ful;
	showSubMenu(ful,sul);
}
function showSubMenu(m_id,s_id)
{
	var ful=document.getElementById(m_id);
	var sul=document.getElementById(s_id);
	if(sul.style.display=="block")
	{
		sul.style.display="none";
	}else{
		for(var i=0;i<NNum;i++)
		{
			var cn=document.getElementById("cmenu_"+i);
			if(cn!=null)
			{
				if(cn.style.display=="block")
				{
					cn.style.display="none";
				}
			}
		}
		sul.style.display="block";
	}
}

function getMenu()
{
	var xmlDoc=createXmlDoc();
	xmlDoc.async = false;   
 	xmlDoc.load("xml/menu.xml"); 
	var mainul=createList("ul","menu_ul","");
 	var nodeNum = xmlDoc.documentElement.getElementsByTagName("node"); 
 	var mDiv=document.getElementById("menuDiv");
 	var qx=document.getElementById("qx");
 	var qxv=qx.getAttribute("value");
 	NNum=nodeNum.length;
 	for(var i=0;i<nodeNum.length;i++)
 	{
 		var node=nodeNum[i];
 		var n_li=createList("li","menu_"+i,"men_li");
 		
 		var text=node.getElementsByTagName("text")[0];
 		var title=node.getElementsByTagName("title")[0].firstChild.data;
 		var link=node.getElementsByTagName("link")[0].firstChild.data;
 		var target=node.getElementsByTagName("target")[0].firstChild.data;
 		var aclick=node.getElementsByTagName("click")[0];
 		var power=node.getElementsByTagName("power")[0];
 		var powerR=(power.firstChild.data).split(',');
 		if(hasPower(powerR,qxv))
 		{
	 		var n_a=createA(title,target,link);
	 		if(aclick.childNodes.length!=0)
	 		{
				if(window.addEventListener){ 
					n_a.setAttribute("onclick",aclick.firstChild.data);
			   } else {
			        n_a.attachEvent('onclick',showSubMenu1);
			    }
	 		}
	 		n_a.innerHTML=text.firstChild.data;
	 		n_li.appendChild(n_a);
	 		mainul.appendChild(n_li);
	 		mDiv.appendChild(mainul);
	 		var cn=node.getElementsByTagName("chirldNode");
	 		
	 		if(cn.length!=0)
	 		{
	 			var c_ul=createList("ul","cmenu_"+i,"subMenu");
		 		for(var j=0;j<cn.length;j++)
		 		{
		 			var cnode=cn[j];
		 			var cn_li=createList("li","","");
		 			
		 			var cpower=cnode.getElementsByTagName("power")[0];
 					var cpowerR=(cpower.firstChild.data).split(',');
 					if(hasPower(cpowerR,qxv))
 					{
			 			var c_text=cnode.getElementsByTagName("text")[0];
				 		var c_title=cnode.getElementsByTagName("title")[0].firstChild.data;
				 		var c_link=cnode.getElementsByTagName("link")[0].firstChild.data;
				 		var c_target=cnode.getElementsByTagName("target")[0].firstChild.data;
				 		var cn_a=createA(c_title,c_target,c_link);
				 		cn_a.innerHTML=c_text.firstChild.data;
				 		cn_li.appendChild(cn_a);
				 		c_ul.appendChild(cn_li);
			 		}
		 		}
		 		n_li.appendChild(c_ul);
		 	}
		 }
 	}
}
function createList(list_type,list_id,list_class)
{
	var list=document.createElement(list_type);
	list.setAttribute("id",list_id);
	list.className=list_class;
	return list;
}
function createA(a_title,a_target,a_href)
{
	var n_a=document.createElement("a");
	n_a.setAttribute("title",a_title);
 	n_a.setAttribute("target",a_target);
 	n_a.setAttribute("href",a_href);
 	return n_a;
}
function hasPower(powerArray,power)
{
	for(var i=0;i<powerArray.length;i++)
	{
		if(power==powerArray[i])
		{
			return true;
		}
	}
	return false;
}